/**
 * 
 */
package com.mindtree.vi.dbaccess.manager;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.orm.jpa.JpaTemplate;

import com.mindtree.vi.dbaccess.datatypes.Datatype;

/**
 * @author venkatesh
 * 
 */
public class BaseTableManager implements TableManager<Datatype> {

	private JpaTemplate jpaTemplate;

	@Required
	public void setJpaTemplate(JpaTemplate jpaTemplate) {
		this.jpaTemplate = jpaTemplate;
	}

	public Datatype delete(long id) {
		return null;
	}

	public Datatype find(Class<? extends Datatype> datatype, long id) {
		return jpaTemplate.find(datatype, id);
	}

	public Datatype save(final Datatype datatype) {
		jpaTemplate.setFlushEager(true);
		jpaTemplate.persist(datatype);
		return datatype;
	}

	public Datatype update(Datatype datatype) {
		return jpaTemplate.merge(datatype);

	}

	public Datatype find(long id) {
		return find(Datatype.class, id);
	}

	public List<? extends Datatype> findAll() {
		   return new ArrayList<Datatype>();
	}

	public List<Datatype> find(String queryString) {
		return jpaTemplate.find(queryString);
	}

	public List<Datatype> find(String query, Map<String, Object> parameterMap) {
		List<Datatype> datatypes = jpaTemplate.findByNamedParams(query,
				parameterMap);
		return datatypes;
	}
}
